
import * as request from "./request.js";
let storage = window.localStorage;
if (!storage) {
	console.log('浏览器版本太低，不支持localStorage');
}
export function upload_form(containerId)
{
  storage.nowHref = "upload";
  const container = document.getElementById(containerId);
  container.innerHTML = "";
  //container.style.textAlign = 'center';
  var input, label, br, span;
  /*
  var a = document.createElement("a");
  a.style.float = 'right';
  a.href = "sign_up.html";
  a.innerHTML = "sign up";
  a.onclick = function() {
    sign_up_form(containerId);
    return false;
  }
  container.appendChild(a);
  br = document.createElement("br");
  container.appendChild(br);
  */
  const form = document.createElement("form");
  form.style.textAlign = 'center';
  container.appendChild(form);
  form.action = "/files";
  form.method = "POST";
  form.id = 'form';
  form.enctype = 'multipart/form-data';
  input = document.createElement("input");
  input.type = "hidden";
  input.id = "option";
  input.name = "text1";
  input.value = "filesUpload";
  form.appendChild(input);
  input = document.createElement("input");
  input.type = "file";
  input.name = "file";
  input.size = "20";
  input.id = "filesInput";
  form.appendChild(input);
  span = document.createElement("span");
  span.style.fontSize = "12pt";
  span.id = "file_info";
  form.appendChild(input);
  br = document.createElement("br");
  form.appendChild(br);
  input = document.createElement("input");
  input.type = "submit";
  input.id = "signIn";
  input.value = "Submit";
  form.appendChild(input);
  form.addEventListener('submit', function(event) {
    event.preventDefault();
    request.post_files_callback("files", "filesInput",
      "token", null, true);
  });
}
